/**
 * Created by lihaoyu on 2017/8/8.
 */
$(document).ready(function(){
    $("#signUp").click(function(){
        if(!/[a-zA-Z0-9]{4,10}/.test($('#ID').val())){
            alert("wrong ID");
            $("#ID").focus();
            return false;
        }
        else if(!/^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}/.test($("#PW").val()))
        {
            console.log($("#PW").val());
            alert("password too easy");
            $("#PW").focus();
            return false;
        }
        else if($("#PW").val()!=$("#PW2").val())
        {
            alert("两次密码不一致");
            $("#PW").focus();
            return false;
        }
        else if(!/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test($("#EMAIL").val()))
        {
            alert("邮箱格式不正确");
            $("#EMAIL").focus();
            return false;
        }
        else{
            var pwMd5 = $.md5($("#PW").val());
            $.ajax({
                type: "POST",
                url: "/process_post",
                dataType:'json',
                data: "ID="+$("#ID").val()+"&PW="+pwMd5+"&EMAIL="+$("#EMAIL").val(),
                success:function(msg){
                    if(msg.same=="1"){
                        $.toast("sign up success",function () {
                            window.location.href="signIn.html";    //跳转到登录页面
                        });
                    }
                    else{
                        alert("same ID");
                        $("#ID").focus();
                        return false;
                    }
                },
                error:function(msg){
                    console.log("error");
                }
            });
        }
    });
});
